/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands;

import org.eclipse.gef.commands.Command;

import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.Property;

/**
 * A command to change GraphNode properties.
 *
 * @author David Servat
 * @since 21 may 07
 */
public class ChangeGraphNodePropertyCommand extends Command{
	
	/**
	 * The debig channel.
	 */
	private int channel = 501;
	
	/**
	 * The property old value.
	 */
	protected String oldValue = "";
	
	/**
	 * The property new value.
	 */
	protected String newValue = "";
	
	/** 
	 * The property whose value is changed.
	 */
	protected Property property = null;
	
	/**
	 * The contsructor, stores the value and parameters.
	 */
	public ChangeGraphNodePropertyCommand(Property property, String newValue){
		super();
		
		Debug.debug(this, "Call ChangeGraphNodePropertyCommand(Property property, String newValue)", channel);
		if((property == null) || (newValue == null))
			throw new IllegalArgumentException();
		
		this.property = property;
		oldValue = property.getValue();
		this.newValue = newValue; 
	}

	/**
	 * Execute method calls redo().
	 */
	@Override
	public void execute(){
		redo();
	}
	
	/**
	 * Does the job.
	 */
	@Override
	public void redo(){
		property.setValue(newValue);
	}
	
	/**
	 * Performs undo.
	 */
	@Override
	public void undo(){
		property.setValue(oldValue);
	}
}
